]> git.neil.brown.name Git - wiggle.git/commitdiff
Test must not expose non-determinism.
authorNeilBrown <neil@brown.name>
Mon, 7 Sep 2020 09:40:52 +0000 (19:40 +1000)
committerNeilBrown <neil@brown.name>
Mon, 7 Sep 2020 09:40:52 +0000 (19:40 +1000)
The recent heuristic to make 'diff' faster introduce non-determinism
which is bad for testing.

So add option to set the loop count rather than having a maximum running
time.

Signed-off-by: NeilBrown <neil@brown.name>
diff.c
dotest

diff --git a/diff.c b/diff.c
index 31d77db8f7fab9c3cd1386652b4666d01009faef..954d3d6f6d16f2d937e1fce523e754801fddf1c7 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -178,9 +178,17 @@ static int find_common(struct file *a, struct file *b,
         */
        int worst = (ahi-alo)+(bhi-blo);
 
+       int loopcount = -1;
        shortcut = !!shortcut;
-       if (shortcut)
-               gettimeofday(&start, NULL);
+       if (shortcut) {
+               char *lc = getenv("WIGGLE_LOOPCOUNT");
+               if (lc)
+                       loopcount = atoi(lc);
+               if (loopcount < 5) {
+                       loopcount = -1;
+                       gettimeofday(&start, NULL);
+               }
+       }
 
        klo = khi = alo-blo;
        v[klo].x = alo;
@@ -191,11 +199,15 @@ static int find_common(struct file *a, struct file *b,
                int cost;
                int k;
 
+               if (loopcount > 0)
+                       loopcount -= 1;
                if (shortcut == 1 &&
                    khi - klo > 5000 &&
-                   gettimeofday(&stop, NULL) == 0 &&
-                   (stop.tv_sec - start.tv_sec) * 1000000 +
-                   (stop.tv_usec - start.tv_usec) > 20000)
+                   (loopcount == 0 ||
+                    (loopcount < 0 &&
+                     gettimeofday(&stop, NULL) == 0 &&
+                     (stop.tv_sec - start.tv_sec) * 1000000 +
+                     (stop.tv_usec - start.tv_usec) > 20000)))
                        /* 20ms is a long time.  Time to take a shortcut
                         * Next snake wins
                         */
diff --git a/dotest b/dotest
index e718f13c9d1e86e16652d42a0bb5159a39eae9cb..1b3a44e0facfccb67842ff825337785571cf098d 100755 (executable)
--- a/dotest
+++ b/dotest
@@ -38,6 +38,9 @@ status=0
 ok=0
 fail=0
 
+# Avoid non-determinism cause by CPU speed
+export WIGGLE_LOOPCOUNT=5000
+
 find . -name core | xargs rm -f
 list=$(find . -type f \( -name script -o -name diff -o -name ldiff \
        -o -name rediff -o -name merge -o -name wmerge -o -name lmerge \